
var windowManager = {
	currentWindow : null,

	/**
	 * {id:'ID', name:'NAME', isShowed:false}
	 * id is the elem id for the window.
	 * name is a short name for that id. XXX : name could not be same.
	 */
	windows : [],
};
windowManager.newWindow = function(id, name){
	var index = windowManager.getWindowIndexById(id);
	if ( -1 != index )
		throw (id + ' window is already exists.' );
	
	index = windowManager.getWindowIndexByNmae(name);
	if ( -1 != index )
		throw (name + ' window is already exists.' );
		
	windowManager.windows.push({id:id, name:name, isShowed:false});
}
windowManager.windowShow = function(name, win){
	var index = windowManager.getWindowIndexByNmae(name);
	
	if ( windowManager.windows[index].isShowed )
		throw ( name + ' is already showed.' );
		
	$('#' + windowManager.windows[index].id).show();
	windowManager.windows[index].isShowed = true;
	
	if ( 'function' == typeof (win._onOpened) )
		win._onOpened();
}
windowManager.windowHide = function(name){
	var index = windowManager.getWindowIndexByNmae(name);
	
	if ( !windowManager.windows[index].isShowed )
		throw ( name + ' is not showed.' );
		
	$('#' + windowManager.windows[index].id).hide();
	windowManager.windows[index].isShowed = false;
}
windowManager.getWindowIndexById = function(id){
	var index = windowManager.windows.length;
	while ( -1 < --index )
		if ( windowManager.windows[index] == id )
			break;
			
	return index;
}
windowManager.getWindowIndexByNmae = function(name){
	var index = windowManager.windows.length;
	while ( -1 < --index )
		if ( windowManager.windows[index].name == name )
			break;
			
	return index;
}


function getSelfHtml( sign ){
	var newId = ("tmp_" + Math.random()).replace(".", "");
	$('<div>', {id:newId}).appendTo('body');
	$(sign).clone().appendTo("#"+newId);
		
	var html = $('#' + newId).html();
	$('#' + newId).remove();
	return html;
}

function stringReplaceAll( sourceString, replaceString, replaceValue ){
	while ( -1 != sourceString.indexOf(reaplaceString) )
		sourceString = sourceString.replace(replaceString, replaceValue);
		
	return sourceString;
}

function now(){
	var nowTime = new Date();
	var year = nowTime.getFullYear();
	var month = nowTime.getMonth() + 1;
	var day = nowTime.getDate();
	var hours = nowTime.getHours();
	var minutes = nowTime.getMinutes();
	var seconds = nowTime.getSeconds();
	
	return year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds;
}

var userAgent = navigator.userAgent.toLowerCase();
// Figure out what browser is being used
jQuery.browser = {
	version: (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [0,'0'])[1],
	safari: /webkit/.test( userAgent ),
	opera: /opera/.test( userAgent ),
	msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
	mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )
};